/*
 * @description:根据时间戳获取显示时间
 * @Author: wxy
 * @Date: 2020-05-07 13:03:38
 */
export default {
  zeroize(num) {
    return (String(num).length == 1 ? '0' : '') + num;
  },
  formatTime(number, format) {
    let time = new Date(number);
    let newArr = [];
    let formatArr = ['Y', 'M', 'D', 'h', 'm', 's'];
    newArr.push(time.getFullYear());
    newArr.push(this.zeroize(time.getMonth() + 1));
    newArr.push(this.zeroize(time.getDate()));
    newArr.push(this.zeroize(time.getHours()));
    newArr.push(this.zeroize(time.getMinutes()));
    newArr.push(this.zeroize(time.getSeconds()));

    for (let i in newArr) {
      format = format.replace(formatArr[i], newArr[i]);
    }
    return format;
  },
  // timestampFormat(timestamp, isFull) {
  //   // console.log('格式化时间', timestamp);
  //   let curTimestamp = new Date().getTime();
  //   let timestampDiff = curTimestamp - timestampDiff;
  //   let curDate = new Date(curTimestamp); // 当前时间日期对象
  //   let tmDate = new Date(timestamp); // 参数时间戳转换成的日期对象
  //   let Y = tmDate.getFullYear(),
  //     m = tmDate.getMonth() + 1,
  //     d = tmDate.getDate();
  //   let CurY = curDate.getFullYear(),
  //     curM = curDate.getMonth() + 1,
  //     curD = curDate.getDate();
  //   if (CurY == Y && curM == m && curD == d) {
  //     return this.formatTime(timestamp, 'h:m:s');
  //   } else {
  //     if (CurY == Y && curM == m) {
  //       if (curD - 1 == d) {
  //         return '昨天 ' + (isFull ? this.formatTime(timestamp, 'h:m') : '');
  //       } else if (curD - 2 == d) {
  //         return '前天 ' + (isFull ? this.formatTime(timestamp, 'h:m') : '');
  //       } else {
  //         return isFull ? this.formatTime(timestamp, 'Y-M-D h:m') : this.formatTime(timestamp, 'Y-M-D');
  //       }
  //     } else {
  //       return isFull ? this.formatTime(timestamp, 'Y-M-D h:m') : this.formatTime(timestamp, 'Y-M-D');
  //     }
  //   }
  // },
};
